<template>
  <!-- 消费记录 -->
  <div class="app-container">
    <el-card class="search-card">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-form-item label="姓名" prop="name">
          <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCardNumber">
          <el-input
            v-model="queryParams.idCardNumber"
            placeholder="请输入身份证号"
            clearable
          />
        </el-form-item>
        <el-form-item label="学校" prop="school">
          <el-input v-model="queryParams.school" placeholder="请输入学校" clearable />
        </el-form-item>
        <el-form-item label="年级" prop="grade">
          <el-input v-model="queryParams.grade" placeholder="请输入年级" clearable />
        </el-form-item>
        <el-form-item label="班级" prop="className">
          <el-input v-model="queryParams.className" placeholder="请输入班级" clearable />
        </el-form-item>
        <el-form-item label="支付时间" prop="searchMonth">
          <el-date-picker
            v-model="queryParams.searchMonth"
            type="month"
            placeholder="选择月"
            format="yyyy-MM"
            value-format="yyyy-MM"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >
            搜索
          </el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="table-card">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
          >
            导出
          </el-button>
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="recordList">
        <el-table-column label="姓名" align="center" prop="name" />
        <el-table-column label="身份证号" align="center" prop="idCardNumber" />
        <el-table-column label="学校" align="center" prop="school" />
        <el-table-column label="年级" align="center" prop="grade" />
        <el-table-column label="班级" align="center" prop="className" />
        <el-table-column label="身份" align="center" prop="identity" />
        <el-table-column label="日期(月)" align="center">
          <template slot-scope="scope">
            <span>{{ queryParams.searchMonth }}</span>
          </template>
        </el-table-column>
        <el-table-column label="小荷包消费(元)" align="center" prop="xhbAmount" />
        <el-table-column label="余额消费(元)" align="center" prop="yeAmount" />
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>
<script>
import { countConsumptionByPerson } from "@/api/order/consumption";
export default {
  name: "Record",
  dicts: ["payment_method", "payment_method", "is_refunded"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 消费记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNumber: null,
        name: null,
        idCardNumber: null,
        snCode: null,
        paymentMethod: null,
        onlineType: null,
        isRefunded: null,
        school: null,
        grade: null,
        className: null,
        searchMonth: "",
      },
      // 表单参数
      form: {
        refundReason: null,
        refundAmount: null,
      },
      // 表单校验
      rules: {
        name: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
        idCardNumber: [{ required: true, message: "身份证号不能为空", trigger: "blur" }],
        personId: [{ required: true, message: "人员ID不能为空", trigger: "blur" }],
        orderNumber: [{ required: true, message: "订单号不能为空", trigger: "blur" }],
        orderAmount: [{ required: true, message: "订单金额不能为空", trigger: "blur" }],
        paymentTime: [{ required: true, message: "支付时间不能为空", trigger: "blur" }],
      },
      userId: "",
      detail: {
        xhb: 0.0,
      },
    };
  },
  created() {
    this.userId = window.sessionStorage.getItem("userId");
    var time = new Date();
    var year = time.getFullYear();
    var month =
      time.getMonth() + 1 < 10 ? "0" + (time.getMonth() + 1) : time.getMonth() + 1;
    this.queryParams.searchMonth = year + "-" + month;
    this.getList();
  },

  activated() {
    this.$forceUpdate();
  },
  methods: {
    /** 查询消费记录列表 */
    getList() {
      this.loading = true;
      countConsumptionByPerson(this.queryParams).then((response) => {
        this.recordList = response.data.list;
        this.total = response.data.count;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
        var obj = {...this.queryParams};
      obj.pageNum=null;
      obj.pageSize=null;
      this.download(
        "/order/consumption/exportAllConsumption",
        {
          ...obj,
        },
        "学生月消费记录" + `_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.iconPublic {
  width: 50px;
}
.searchBox {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
</style>
